package com.lovi.thread_;


/**
 * 体会静态代理
 * 用实现Runable的方法来启动线程
 */
public class Test02 {
    public static void main(String[] args) {
        Dog dog = new Dog();
//        dog.start()【直接这样无法启动线程，需要放到里面】
        /*
        //因为我们的线程类构造方法:
        public Thread(Runnable target) {
                init(null, target, "Thread-" + nextThreadNum(), 0);
        }
        而我们的Dog类实现了Runable接口，所以可以放进去
         */
        Thread thread = new Thread(dog);
        thread.start();//开启线程

    }
}

class Dog implements Runnable {

    @Override
    public void run() {
        int count = 0;
        while (true) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("汪汪,我是小狗," + (++count) + "线程名："
                    + Thread.currentThread().getName());
            if (count == 50) {
                break;
            }
        }
    }
}
